﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Codeplex.Unity.AutoRegister.Config;

namespace Codeplex.Unity.AutoRegister.Test.Config
{
    [TestClass]
    public class RegistTypeTraitProviderTest
    {
        [TestMethod]
        public void TestMethod1()
        {
            var provider = new TestRegistTypeTraitProvider();
            var traits = provider.GetRegistTypeTraits().ToArray();
            traits.Length.Is(2);
            traits[0].Is(o => o.FromType == typeof(Drived) && o.ToType == typeof(Drived));
            traits[1].Is(o => o.FromType == typeof(Base) && o.ToType == typeof(Drived2));
        }

        class TestRegistTypeTraitProvider : RegistTypeTraitProvider
        {
            protected override IEnumerable<Type> GetTypes()
            {
                yield return typeof(Drived);
                yield return typeof(Drived2);
            }

            protected override IEnumerable<RegistTypeTrait> BuildTrait(Type type)
            {
                if (type == typeof(Drived))
                {
                    yield return new RegistTypeTrait(type);
                }
                else
                {
                    yield return new RegistTypeTrait(type) { FromType = typeof(Base) };
                }
            }
        }

        class Base { }
        class Drived : Base { }
        class Drived2 : Base { }
    }

}
